package com.zhanggm.ry.rys1.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.zhanggm.ry.rys1.entity.Dept;
import com.zhanggm.ry.rys1.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2023-04-23
 */
@RestController
@RequestMapping("/s1/dept")
public class DeptController extends BaseController {

    @Autowired
    private IDeptService deptService;

    @GetMapping("getById")
    @SentinelResource(value = "ry-s1",blockHandler = "blockHandler",fallback = "fallback")
    public R<Dept> getById(@RequestParam("id") Integer id) {
        logger.info("部门Id:{}", id);
        return R.ok(deptService.getById(id));
    }


    public R<Dept> blockHandler(Integer id, BlockException blockException) {
        blockException.printStackTrace();
        return R.fail("限流了");
    }

    public R<Dept> fallback(Integer id, Throwable throwable) {
        throwable.printStackTrace();
        return R.fail("熔断了");
    }
}
